package com.whut.monitor.util.predictor.bpnn;

/**
 * Created by WSJ on 2017/11/28.
 */
public class BpPredictor {

    /**
     * 调用该函数即可训练并得到预测结果
     * @param dataPath
     * 数据文件格式为：每一行为一组数据，每组数据的第一个为期望值，其余为输入值，数据之间以","分隔，每组数据以换行分隔
     */
    public static void trainAndPredict(String dataPath , String predictPath) {
        String fileName = "D:\\Library\\BpNeuralNetwork-digtal_lable\\sample-data\\excel7-7.csv";
        Dataset dataset = Dataset.load(fileName, ",", 0, false);
        BPNetwork bp = new BPNetwork(new int[] { 8, 6, 1 }, false);
        //threshold为允许误差，一般收敛到0.98附近
        bp.trainModel(dataset, 0.9755);
        String testName = "D:\\Library\\BpNeuralNetwork-digtal_lable\\sample-data\\excel7-10.csv";
        Dataset testset = Dataset.load(testName, ",", 0, false);
        //输出文件名
        String outName = "sample-data/func_test.predict";
        bp.predict(testset, outName);
        ConcurenceRunner.stop();
    }

}
